package graph.entities;

import static ogl.vecmathimp.FactoryDefault.vecmath;
import graph.Entity;
import graph.Part;
import ogl.vecmath.Matrix;
import ogl.vecmathimp.MatrixImp;

public class Jumper extends Entity {
	private float upMovement;
	private float downMovement;

	public Jumper(Part p) {
		super(p);
	}
	
	@Override
	synchronized public void simulate(EntityType et, float duration) {
		MatrixImp modelMatrix = super.getPart().getMatrix().getTranslation();
		
		if (et == EntityType.JumpUp) {
			// Jump is still going up
			if (duration < 0.5) {
				float y = duration/5;
				upMovement += y;
				Matrix jumpUp = vecmath.translationMatrix(0,y,0);
				modelMatrix = (MatrixImp) modelMatrix.mult(jumpUp);
				this.getPart().setMatrix(modelMatrix);
			// Jump is going down
			} else {
				float y = (float) ((duration - 0.5) / 5);
				if ((downMovement + y) > upMovement) {
					y = upMovement - downMovement;
				}
				downMovement += y;
				Matrix jumpDown = vecmath.translationMatrix(0,-y,0);
				modelMatrix = (MatrixImp) modelMatrix.mult(jumpDown);
				this.getPart().setMatrix(modelMatrix);
			}	
		}		
	}

}
